#ifndef PLAYER_H
#define PLAYER_H

#include "villagetile.h"
#include <QObject>
#include <QGraphicsObject>
#include <QPixmap>
#include <QDialog>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QList>
#include <QPainter>
#include <QStyleOptionGraphicsItem>

class player;
class playerManager;
class playerInfo;
class PlayerIcon;

class player : public QGraphicsObject
{

    Q_OBJECT

    Q_PROPERTY(QString imagePath READ getImagePath CONSTANT)
    Q_PROPERTY(QString playerName READ getName  CONSTANT)
    Q_PROPERTY(QString playerID  READ getID CONSTANT)
    Q_PROPERTY(int resist0  READ getResist0 WRITE setResist0)
    Q_PROPERTY(int resist1  READ getResist1 WRITE setResist1)
    Q_PROPERTY(int resist2  READ getResist2 WRITE setResist2)
    Q_PROPERTY(int resist3  READ getResist3 WRITE setResist3)
    Q_PROPERTY(int resist4  READ getResist4 WRITE setResist4)
    Q_PROPERTY(int qi  READ getQi WRITE setQi)
    Q_PROPERTY(int yingyang  READ getYingyang WRITE setYingyang)
    Q_PROPERTY(int budda  READ getBudd WRITE setBudda)
    Q_PROPERTY(int positionx  READ getPx WRITE setPx)
    Q_PROPERTY(int positiony  READ getPy WRITE setPy)
    Q_PROPERTY(bool skillUsed READ isskillUsed WRITE setSkilled)
    Q_PROPERTY(bool dead READ isDead WRITE setDead)
    Q_PROPERTY(PlayerColor color READ getColor CONSTANT)

    Q_ENUMS(PlayerColor)
public:
    enum PlayerColor
    {
        RED,
        YELLOW,
        BLUE,
        GREEN
    };

    player(
        QGraphicsObject* parent,
        QString path, QString name, QString id, PlayerColor color,bool skillUsed,
        int resist0, int resist1, int resist2, int resist3, int resist4,
        int buddhaNum, int YinyangNum, int qiNum,int positionx, int positiony,const QPixmap &iconPix);

    int            getResist0      () { return _resist0; }
    int            getResist1      () { return _resist1; }
    int            getResist2      () { return _resist2; }
    int            getResist3      () { return _resist3; }
    int            getResist4      () { return _resist4; }
    int            getQi           () { return _qiNum;}
    int            getYingyang     () { return _yingyangNum;}
    int            getBudd         () { return _buddhaNum;}
    int            getPx           () { return _px;}
    int            getPy           () { return _py;}

    QString        getID           () { return _playerid; }
    QString        getName         () { return _playername; }
    QString        getImagePath    () { return _imgpath; }

    void           setResist0      (int r) {_resist0 = r;}
    void           setResist1      (int r) {_resist1 = r;}
    void           setResist2      (int r) {_resist2 = r;}
    void           setResist3      (int r) {_resist3 = r;}
    void           setResist4      (int r) {_resist4 = r;}
    void           setQi           (int q) {_qiNum = q;}
    void           setYingyang     (int y) {_yingyangNum = y;}
    void           setBudda        (int b) {_buddhaNum = b;}
    void           setPx           (int x) {_px = x;}
    void           setPy           (int y) {_py = y;}
    void           setSkilled      (bool s) {_skilled = s;}
    void           setDead         (bool d) {_isDead = d;}
    PlayerColor    getColor        () { return _playercolor; }
    bool           isskillUsed     () { return _skilled; }
    bool           isDead          () { return _isDead; }


    void yingyangChange(bool isIncease);
    void qiChange(bool isIncease);
    void checkDead();
    void resistChange0(bool isIncease);
    void resistChange1(bool isIncease);
    void resistChange2(bool isIncease);
    void resistChange3(bool isIncease);
    void resistChange4(bool isIncease);
    QPoint setTilePos(PlayerColor color);

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QRectF boundingRect() const;

    static QString ColorToString ( PlayerColor c );
    static QString ColorToSkillString ( PlayerColor c );
private:  
    QString       _imgpath;
    QString       _playername;
    QString       _playerid;
    PlayerColor   _playercolor;
    QPixmap       _iconPix;
    QPoint        _tilePos;
    int           _resist0;
    int           _resist1;
    int           _resist2;
    int           _resist3;
    int           _resist4;
    int           _qiNum;
    int           _yingyangNum;
    int           _buddhaNum;
    int           _px;
    int           _py;
    bool          _isDead;
    bool          _skilled;
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void moveAnim(VillageTile* vt);
signals:
    void pressed();
protected slots:
    void makeAmove();
    void makeAact();


};

/*
class PlayerInfo : public QWidget
{
    Q_OBJECT
public:
    PlayerInfo(player::PlayerColor color);
public slots:
    void displayPlayerInfo(player::PlayerColor color);
    void buttonClicked();
private:
    QList <player*> _testdeck;

    QVBoxLayout* _mainlayout;
    QGridLayout* _infolayout;
    player*  _testPlayer;

    QLabel* _imglabel;

    QLabel* _idlabel;
    QLabel* _namelabel;
    //QLabel* _colorlabel;

    //QLabel* _pskilllabel;

    QLabel* _rredlabel;
    QLabel* _ryellabel;
    QLabel* _rblulabel;
    QLabel* _rgrelabel;
    QLabel* _rblalabel;

    QLabel* _qilabel;
    QLabel* _yingyanglabel;
    QLabel* _buddlabel;
};
*/

#endif // PLAYER_H
